package xdu.lz.stage5_jucUtils.chapter2_cycliBarrier;


import java.util.concurrent.CountDownLatch;

/**
 * Created at 2019/10/18 0018 下午 5:19
 *
 * 回调实现
 */
public class CB_test3_callbackfunction extends CountDownLatch {

    private Runnable runnable;
    public CB_test3_callbackfunction(int count,Runnable runnable) {
        super(count);
        this.runnable = runnable;
    }

    @Override
    public void countDown() {
        super.countDown();
        // 回调方法
        if(this.getCount() == 0){
            this.runnable.run();
        }
    }
}
